package servlet;

import java.io.IOException;

//import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.codehaus.xfire.XFireFactory;
//import org.codehaus.xfire.client.XFireProxyFactory;
//import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import org.bminfo.migle.parser.ExSingleInfo;

public class DataServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public DataServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String folderName = request.getParameter("folderName");
		String miGLE_home = request.getSession().getAttribute("miGLE_home").toString();
		String site = request.getParameter("site");
		String startIndex = request.getParameter("startIndex");
		String type = request.getParameter("type");
		
//		org.codehaus.xfire.service.Service srvcModel = new ObjectServiceFactory().create(IMigleServer.class);
//		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
//		String moopsServiceURL = "http://" + request.getServerName().toString() + ":"
//		+ request.getServerPort() + "/miGLE/services/MoopsServer";
//		IMigleServer srvc = (IMigleServer)factory.create(srvcModel, moopsServiceURL);
		
		String sitenumber = Integer.valueOf(Integer.parseInt(site) + Integer.parseInt(startIndex)).toString();
		
		ExSingleInfo exsingle = new ExSingleInfo();
		
		exsingle.setPath(miGLE_home,folderName);
		exsingle.exSingleInfo(sitenumber, type);
		
//        RequestDispatcher rd = request.getRequestDispatcher("../temp/" + folderName + "/list/" + sitenumber + ".html");   
//        rd.forward(request, response); 
		
		response.sendRedirect("../temp/" + folderName + "/list/" + sitenumber + ".html");
        
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
